package cn.iocoder.yudao.module.vos.controller.admin.secretrechargerecord;

import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.vos.controller.admin.secretrechargerecord.vo.*;
import cn.iocoder.yudao.module.vos.dal.dataobject.secretrechargerecord.SecretRechargeRecordDO;
import cn.iocoder.yudao.module.vos.service.secretrechargerecord.SecretRechargeRecordService;

@Tag(name = "管理后台 - 密钥充值记录")
@RestController
@RequestMapping("/vos/secret-recharge-record")
@Validated
@TenantIgnore
public class SecretRechargeRecordController {

    @Resource
    private SecretRechargeRecordService secretRechargeRecordService;

    @PostMapping("/create")
    @Operation(summary = "创建密钥充值记录")
    @PreAuthorize("@ss.hasPermission('vos:secret-recharge-record:create')")
    public CommonResult<Long> createSecretRechargeRecord(@Valid @RequestBody SecretRechargeRecordSaveReqVO createReqVO) {
        return success(secretRechargeRecordService.createSecretRechargeRecord(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新密钥充值记录")
    @PreAuthorize("@ss.hasPermission('vos:secret-recharge-record:update')")
    public CommonResult<Boolean> updateSecretRechargeRecord(@Valid @RequestBody SecretRechargeRecordSaveReqVO updateReqVO) {
        secretRechargeRecordService.updateSecretRechargeRecord(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除密钥充值记录")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('vos:secret-recharge-record:delete')")
    public CommonResult<Boolean> deleteSecretRechargeRecord(@RequestParam("id") Long id) {
        secretRechargeRecordService.deleteSecretRechargeRecord(id);
        return success(true);
    }

    @DeleteMapping("/delete-list")
    @Parameter(name = "ids", description = "编号", required = true)
    @Operation(summary = "批量删除密钥充值记录")
                @PreAuthorize("@ss.hasPermission('vos:secret-recharge-record:delete')")
    public CommonResult<Boolean> deleteSecretRechargeRecordList(@RequestParam("ids") List<Long> ids) {
        secretRechargeRecordService.deleteSecretRechargeRecordListByIds(ids);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得密钥充值记录")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('vos:secret-recharge-record:query')")
    public CommonResult<SecretRechargeRecordRespVO> getSecretRechargeRecord(@RequestParam("id") Long id) {
        SecretRechargeRecordDO secretRechargeRecord = secretRechargeRecordService.getSecretRechargeRecord(id);
        return success(BeanUtils.toBean(secretRechargeRecord, SecretRechargeRecordRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得密钥充值记录分页")
    @PreAuthorize("@ss.hasPermission('vos:secret-recharge-record:query')")
    public CommonResult<PageResult<SecretRechargeRecordRespVO>> getSecretRechargeRecordPage(@Valid SecretRechargeRecordPageReqVO pageReqVO) {
        PageResult<SecretRechargeRecordDO> pageResult = secretRechargeRecordService.getSecretRechargeRecordPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, SecretRechargeRecordRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出密钥充值记录 Excel")
    @PreAuthorize("@ss.hasPermission('vos:secret-recharge-record:export')")
    @ApiAccessLog(operateType = EXPORT)
    public void exportSecretRechargeRecordExcel(@Valid SecretRechargeRecordPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<SecretRechargeRecordDO> list = secretRechargeRecordService.getSecretRechargeRecordPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "密钥充值记录.xls", "数据", SecretRechargeRecordRespVO.class,
                        BeanUtils.toBean(list, SecretRechargeRecordRespVO.class));
    }

}